import { Base } from '../../utils/base.js';

class Cart extends Base {

  constructor() {
    super();
    this._storageKeyName = 'cart';
  }
  // 加入到购物车
  addCart(callback, options) {
    var params = {
      url: 'post/addCart',
      data: options.data,
      type: options.type,
      sCallback: function (res) {
        callback && callback(res);
      }
    }
    this.request(params);
  }
  // 获取购物车数据
  getCartData(callback, session3rd) {
    var params = {
      url: 'getCart?session3rd=' + session3rd,
      sCallback: function (res) {
        callback && callback(res);
      }
    }
    this.request(params);
  }

	// 增加商品数目
  addCounts(callback, data) {
    var params = {
      url: 'post/addCart',
      type:'POST',
      data,
      sCallback: function (res) {
        callback && callback(res);
      }
    }
    this.request(params);
  }

	// 减少商品数目
  cutCounts(callback, data) {
    var params = {
      url: 'post/reduce',
      type: 'POST',
      data,
      sCallback: function (res) {
        callback && callback(res);
      }
    }
    this.request(params);
  }
  // 删除商品
  delete(callback, data) {
    var params = {
      url: 'post/destroyCart',
      type: 'POST',
      data,
      sCallback: function (res) {
        callback && callback(res);
      }
    }
    this.request(params);
  }

}

export { Cart };